package business {
	
	import flash.events.Event;
	
	import routes.ApplicationEvent;
	
	public class StockQuoteManager {
		
		public function StockQuoteManager() {}
		
		public function getQuoteForSymbol(ae:ApplicationEvent):void {
			var symbol:String = String(ae.getItem("symbol"));
			// do the service call needed to get the quote for the specified 
			// stock symbol, and setting the success handler to be called...
			// 
			// for the sake of this example, we simply simulate the callback
			var gotQuoteHandler:Function = getHandler_gotQuoteHandler(ae);
			gotQuoteHandler(null);
		}
		
		internal function getHandler_gotQuoteHandler(
			aeRequest:ApplicationEvent
		):Function {
			function gotQuoteHandler(event:Event):void {
				// retrieve the received quote value from the received event --
				// for the sake of this example, we just simulate the 
				// incoming quote data...
				var quote:Number = Math.random() * 100;
				
				// set onto a newly yielded ApplicationEvent and dispatch --
				// we do this by simply "pushing" a new ApplicationEvent onto
				// the requesting ApplicationEvent, thus effectively creating 
				// an ApplicationEvent stack that retains the entire event
				// trace and data (in this case, the requested symbol)
				var ae:ApplicationEvent = aeRequest.yield("gotStockQuote");
				// trace("Requested symbol:", ae.getItem("symbol"));
				ae.setItem("quote", quote);
				g.routes.dispatchEvent(ae);
			}
			return gotQuoteHandler;
		}
	
	}
	
}
